package com.ysu.his.admin.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ysu.his.admin.mapper.DepartmentMapper;
import com.ysu.his.admin.mapper.DepartmentUserMapper;
import com.ysu.his.admin.service.DepartmentService;
import com.ysu.his.dto.DepartmentDto;
import com.ysu.his.entity.user.Department;
import com.ysu.his.dto.UserDepartmentDto;
import com.ysu.his.vo.UserVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DepartmentServiceImpl implements DepartmentService
{
    @Autowired
    private DepartmentMapper departmentMapper;

    @Autowired
    private DepartmentUserMapper departmentUserMapper;


    @Override
    public PageInfo<Department> getDepartmentByPage(Integer page, Integer limit, DepartmentDto departmentDto)
    {
        PageHelper.startPage(page, limit);

        List<Department> departmentList = departmentMapper.getDepartmentByPage(departmentDto);

        PageInfo<Department> pageInfo=new PageInfo<>(departmentList);
        return pageInfo;
    }

    @Override
    public void addDepartment(Department department)
    {
        departmentMapper.addDepartment(department);
    }

    @Override
    public List<UserVo> getDoctorByDepartmentId(Long departmentId)
    {
        List<UserVo> userVoList = departmentMapper.getDoctorByDepartmentId(departmentId);

        return userVoList;
    }

    @Override
    public void addDoctorToDepartment(UserDepartmentDto userDepartmentDto)
    {
        departmentUserMapper.addDoctorToDepartment(userDepartmentDto.getDepartmentId(),userDepartmentDto.getUserIdList());
    }

    @Override
    public List<Department> getAllDepartment()
    {
        return departmentMapper.getAllDepartment();

    }
}
